#include <avr/interrupt.h>
#include <avr/io.h>

#include "timers.h"

volatile uint16_t T2_HCOUNTER; 
volatile uint8_t T2_TASK_FLAG;

ISR(TIMER2_OVF_vect) {

  T2_HCOUNTER++;
  if (T2_HCOUNTER>T2_HCNT_MAX) {
    T2_TASK_FLAG = 1;
    T2_HCOUNTER = 0;
  }
  
}

void timer2_init(void){

  /*  8 pre-scaler */
  TCCR2B |= (1<<CS21);
  /* Enable Timer Overflow Interrupts */
  TIMSK2 |= _BV(TOIE2);
  /* Reset Counters */
  TCNT2 = 0;
  T2_HCOUNTER = 0;
  T2_TASK_FLAG = 0;

}
